{% extends 'base.html' %}

{% block title %}{{ title }} - EasyTesting{% endblock %}

{% block header %}{{ title }}{% endblock %}

{% block content %}
<div class="row justify-content-center">
    <div class="col-md-8">
        <div class="card">
            <div class="card-body p-4">
                <form method="post">
                    {% csrf_token %}
                    
                    <div class="mb-4">
                        <label for="{{ form.name.id_for_label }}" class="form-label fw-medium">分组名称</label>
                        {{ form.name.errors }}
                        <input type="text" class="form-control form-control-lg" id="{{ form.name.id_for_label }}" name="{{ form.name.html_name }}" value="{{ form.name.value|default:'' }}" required placeholder="输入分组名称">
                        <div class="form-text">测试用例分组名称</div>
                    </div>
                    
                    {{ form.project }}
                    
                    <div class="mb-4">
                        <label for="{{ form.parent.id_for_label }}" class="form-label fw-medium">上级分组</label>
                        {{ form.parent.errors }}
                        <select class="form-select" id="{{ form.parent.id_for_label }}" name="{{ form.parent.html_name }}">
                            <option value="">无上级分组 (默认根分组)</option>
                            {% for choice in form.parent.field.choices %}
                                {% if choice.0 %}
                                    <option value="{{ choice.0 }}" {% if form.parent.value|stringformat:"s" == choice.0|stringformat:"s" %}selected{% endif %}>{{ choice.1 }}</option>
                                {% endif %}
                            {% endfor %}
                        </select>
                        <div class="form-text">如果这是子分组，请选择父分组</div>
                    </div>
                    
                    <div class="d-flex justify-content-between mt-4">
                        <a href="{% url 'test_case_list' %}?project={{ project.id }}" class="btn btn-outline-secondary">
                            <i class="bi bi-arrow-left"></i> 取消
                        </a>
                        <button type="submit" class="btn btn-primary px-4">
                            <i class="bi bi-check-lg"></i> 保存
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %}
